<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if(!isset($_SESSION['member_id']))
    echo"<script type='text/javascript'>top.window.location='index.php';</script>";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="functions.js"></script>
        <?php include_once "jquery.php";?>
        <script type="text/javascript">
            $(document).ready(function()
            {
                check_top();
                $(".highlight").bind("mouseenter",function()
                {
                    $(this).parent("tr").find("td").css("background-color", "#003366");
                    $(this).parent("tr").find("td,a").css("color", "white");
                });
                $(".highlight").bind("mouseleave", function()
                {
                    $(this).parent("tr").find("td").css("background-color", "white");
                    $(this).parent("tr").find("td,a").css("color", "#003366");
                });
            });
        </script>
        <title></title>
    </head>
    <body>
        <?php
        if(isset($_SESSION['lang']))
            require_once "./language_files/userHomepage_" . $_SESSION['lang'] . ".php";
        else
            require_once "./language_files/userHomepage_en.php";

        require_once "functions.php";
        //establishing  a database connection
        //getting the id of the current member
        $member_id=$_SESSION['member_id'];
        //execute query to display the conferences of this user and his role in each conference
        $result=mysql_query("SELECT DISTINCT c.conference_date, c.long_name, c.conference_id
        FROM  conference c INNER JOIN member_privileges p ON (p.conference_id = c.conference_id)
        WHERE p.member_id = $member_id ORDER BY c.conference_date DESC") or die(mysql_error());

        echo '<table style="width:100%;">
            <tr>
                <td style="background-color:#003366; color:white; text-align:center;"><b>' . $lang['conf'] . '</b></td>
                     <td style="background-color:#003366; color:white; text-align:center;"><b>' . $lang['date'] . '</b></td>
                                              <td style="background-color:#003366; color:white; text-align:center;"><b>' . $lang['role'] . '</b></td>

            </tr>';
        //printing each value
        while($row=mysql_fetch_assoc($result))
        {
            $conf_date=formatText_safe($row['conference_date']);
            $d=strtotime($conf_date);
            $date=date("D-d-M-Y",$d);
            $role=mysql_query("SELECT p.role from privileges p  INNER JOIN member_privileges m ON (m.privileges_id = p.privileges_id)
                WHERE m.member_id = $member_id AND m.conference_id = {$row['conference_id']}") or die(mysql_error());
            $author="";
            $organizer="";
            $reviewer="";
            while($r=mysql_fetch_assoc($role))
            {
                $rl=$r['role'];
                if($rl == 'author')
                {
                    $author=$lang['author'];
                }
                if($rl == 'organizer')
                {
                    $organizer=$lang['organizer'];
                }
                if($rl == 'reviewer')
                {
                    $reviewer=$lang['reviewer'];
                }
            }

            $role=$author . $organizer . $reviewer;
            if($rl == 'attendee')
            {
                $long=formatText_safe($row['long_name']);
                echo "<tr>
                <td class='highlight'><a href='conferencePage2.php?conference_id={$row['conference_id']}'>{$long}</a> </td>
                 <td class='highlight'>$date</td>
                <td class='highlight'>" . $lang['attendee'] . "</td>
                 </tr>";
            }
            else
            {
                $long=formatText_safe($row['long_name']);
                echo "<tr>
                <td class='highlight'><a href='subscriberConferencePage.php?conference_id={$row['conference_id']}'>{$long}</a> </td>
                 <td class='highlight'> $date</td>
                <td class='highlight'>$role</td>
            </tr>";
            }
        }
        echo "</table>";
        ?>
    </body>
</html>